package com.xiye.im.controller;

import com.xiye.common.entity.User;
import com.xiye.common.util.Const;
import com.xiye.common.util.Jurisdiction;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Package com.xiye.im.controller
 * @Description 即时通讯请求
 * @Author 西野
 * @Date 2018-09-13
 * @Version V1.0
 */
@Controller
public class IndexController {

    @RequestMapping("/")
    public String login(){
        return "index/login";
    }

    @RequestMapping("login")
    public String login(HttpServletRequest request,Model model){
        chat(request,model);
        return "index/login";
    }

    @RequestMapping("chat")
    public String chat(HttpServletRequest request,Model model){
        User user = Jurisdiction.getUser(Const.SESSION_USER); // 读取session中的用户信息(单独用户信息)
        String username = (user == null) ? request.getParameter("username") : user.getNAME();
        if (StringUtils.isEmpty(username)) {
            return "index/login";
        }
        model.addAttribute("username",username);
        return "index/chat";
    }

}
